﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>设置隐藏与显示</title>
    <link rel="stylesheet" type="text/css" href="../../Scripts/easyUI145/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/easyUI145/themes/icon.css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../../Scripts/easyUI145/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/easyUI145/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../../Scripts/EasyUIUtility.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../Scripts/Cookie.js"></script>
    <script type="text/javascript" src="../../Scripts/QueryString.js"></script>
    <!--<link href="../Style/CommStyle.css" rel="stylesheet" type="text/css" />-->
    <link href="../../Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />
    <script src="../JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <!-- 该文件可以被集成厂商自己定义风格,可以自己修改,以达到流程设计器与自己的系统风格统一. -->
    <link href="../../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <!-- 位置必须放在 jquery 之后. -->
    <script type="text/javascript" src="../../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../Gener.js"></script>
    <style type="text/css">
        .textbox-addon {
            position: absolute;
        }
        label{
            font-weight:normal;
        }
        .textbox-text {
            margin: 0px 26px 0px 0px;
            padding-top: 0px;
            padding-bottom: 0px;
            height: 28px !important;
            line-height: 28px !important;
        }
        .Sum{
           padding-left:26px;
        }
        .style1 {
            width: 326px;
            
        }
    </style>
    <script type="text/javascript">

        var frmData;
        var mapData;
        var mainData;
        var dtM; //方法集合.
        var pkVal = "";
        var groupFuncs = [];
        var webUser = new WebUser();
        $(function () {

            var httpHandler = new HttpHandler("BP.WF.HttpHandler.WF_CommEntity");
            httpHandler.AddUrlData();
            var data = httpHandler.DoMethodReturnString("EntityOnly_Init");
            if (data.indexOf('err@') == 0) {
                $("#docs").html(data);
                return;
            }

            //解析json.
            frmData = JSON.parse(data);

            mapData = frmData["Sys_MapData"][0];
            mapData = new Entity("BP.Sys.MapData", mapData); //把他转化成entity.
            mainData = frmData["MainData"];
            dtM = frmData["dtM"];

            var str = "";
            var num = 0;
            //循环提取功能分组
            for (var n = 0; n < dtM.length; n++) {
                var groupName = dtM[n].GroupName;
                if (groupName == null) {
                    groupName = "基本信息";
                }
                if (str.indexOf(',' + groupName) >= 0) {
                    continue;
                }
                str += "," + groupName;

                var row = {};
                row.id = "dtM_" + groupName;
                row.name = groupName;
                groupFuncs.push(row);
                num++;
            }
            document.title = mapData.Name;

            Help();

        })

        function Help() {

            var html = "<h3>帮助说明</h3>";
            html += "<ul>";
            html += "<li>如果您想屏蔽部分字段与属性，可以通过该功能实习实现.</li>";
            html += "<li>当我们不想看到自己不关心的字段，或者功能的时候，可以通过设置来实现。</li>";
            html += "</ul>";

            $("#docs").html(html);
        }

        //字段查询.
        function Fields() {
            var enName = GetQueryString("EnName");
            //获得字段列表.
            var Sys_MapAttr = frmData["Sys_MapAttr"];
            //获取字段分组
            var Sys_GroupField = frmData["Sys_GroupField"];

            var mypk = webUser.No + "_Fields_HS_" + enName;
            var cfgEn = new Entity("BP.Sys.UserRegedit");
            cfgEn.SetPKVal(mypk);
            cfgEn.RetrieveFromDBSources();

            var html = "";
            html += "<table width='100%'>";
            //html += "<caption>字段</caption>";
            html += "<thead>";
            html += "<tr>";
            html += "<th>序</th>";
            html += "<th>字段名</th>";
            html += "<th>中文名</th>";
            html += "</tr>";
            html += "</thead>";
            //遍历字段分组
            for (var j = 0; j < Sys_GroupField.length; j++) {
                var groupField = Sys_GroupField[j];
                var checked = "";
                if (cfgEn.MVals.indexOf(',' + groupField.OID) >= 0)
                    checked = " checked=true ";
                html += "<tbody>";
                html += "<tr>";
                html += "<td colspan = '3' class=Sum ><label><input type=checkbox " + checked + " name='FieldGroup' id='" + groupField.OID + "' onclick='swapCheck(\"" + groupField.OID + "\")'/>" + groupField.Lab + "</label></td>";
                html += "</tr>";
                html += "</tbody>";
                html += "<tbody id = '" + groupField.OID + "_All'>";
                //遍历字段
                for (var i = 0; i < Sys_MapAttr.length; i++) {
                    var mapAttr = Sys_MapAttr[i];
                    if (groupField.OID == mapAttr.GroupID) {

                        html += "<tr>";
                        html += "<td>" + (i + 1) + "</td>";

                        var checked = "";
                        var cfgEnVals = cfgEn.Vals.split(",");
                        for (var k = 0; k < cfgEnVals.length; k++) {
                            if (cfgEnVals[k] == mapAttr.KeyOfEn) {
                                checked = " checked=true ";
                            }
                        }

                        html += "<td><label><input type=checkbox " + checked + " name='FieldAttr' id='" + mapAttr.KeyOfEn + "' />" + mapAttr.Name + "</label></td>";
                        html += "<td>" + mapAttr.KeyOfEn + "</td>";

                        html += "</tr>";

                    }
                }
                html += "</tbody>";
            }
            html += "</table>";
            html += "<input type=button onclick='SaveFields();' value='保存' />";

            $("#docs").html(html);




        }
        //复选框全选反选
        function swapCheck(oid) {
            var obj = document.getElementById(oid);
            if (obj != null && obj != undefined && obj.checked) {
                $("#" + oid + "_All").find("input:checkbox").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                $("#" + oid + "_All").find("input:checkbox").each(function () {
                    $(this).prop("checked", false);
                });
            }
        };
        //保存字段
        function SaveFields() {
            var enName = GetQueryString("EnName");
            var mypk = webUser.No + "_Fields_HS_" + enName;
            var cfgEn = new Entity("BP.Sys.UserRegedit");
            cfgEn.SetPKVal(mypk);
            cfgEn.RetrieveFromDBSources();


            //求出来需要所有隐藏的分组.
            var Mkeys = ",";
            $.each($('input:checkbox[name=FieldGroup]:checked'), function (i, obj) {
                Mkeys += obj.id + ",";
            });
            //求出来所有隐藏的字段.
            var keys = ",";
            $.each($('input:checkbox[name=FieldAttr]:checked'), function (i, obj) {
                keys += obj.id + ",";
            });

            cfgEn.FK_Emp = webUser.No;
            cfgEn.CfgKey = 'Fields_HS';
            cfgEn.FK_MapData = enName;
            cfgEn.MVals = Mkeys;
            cfgEn.Vals = keys;
            cfgEn.Save();
            alert('保存成功.');

        }
        //功能查询
        function Funcs() {
            //获得字段列表.
            var dtM = frmData["dtM"];
            //获取字段分组


            var enName = GetQueryString("EnName");

            // HS 标识 hidden show .

            var mypk = webUser.No + "_Funcs_HS_" + enName;
            var cfgEn = new Entity("BP.Sys.UserRegedit");
            cfgEn.SetPKVal(mypk);
            cfgEn.RetrieveFromDBSources();

            var html = "";
            html += "<table width='100%'>";
            html += "<thead>";
            html += "<tr>";
            html += "<th>序</th>";
            html += "<th>功能名</th>";
            html += "</tr>";
            html += "</thead>";

            //遍历功能分组
            for (var j = 0; j < groupFuncs.length; j++) {
                var groupFunc = groupFuncs[j];
                var checked = "";
                if (cfgEn.MVals.indexOf(',' + groupFunc.id) >= 0)
                    checked = " checked=true ";
                html += "<tbody>";
                html += "<tr class='Sum' >";
                html += "<td colspan = '2'><label><input type=checkbox " + checked + " name='FuncGroup' id='" + groupFunc.id + "' onclick='swapCheck(\"" + groupFunc.id + "\")'/>" + groupFunc.name + "</label></td>";
                html += "</tr>";
                html += "</tbody>";
                html += "<tbody id = '" + groupFunc.id + "_All'>";
                //遍历功能
                for (var i = 0; i < dtM.length; i++) {
                    var funcs = dtM[i];
                    if (funcs.GroupName == null) {
                        funcs.GroupName = "基本信息";
                    }
                    if (groupFunc.name == funcs.GroupName) {

                        html += "<tr>";
                        html += "<td>" + (i + 1) + "</td>";

                        var checked = "";
                        var cfgEnVals = cfgEn.Vals.split(",");
                        for (var k = 0; k < cfgEnVals.length; k++) {
                            if (cfgEnVals[k] == funcs.No) {
                                checked = " checked=true ";
                            }
                        }

                        html += "<td ><label><input type=checkbox " + checked + " name='FuncMethod' id='" + funcs.No + "' />" + funcs.Title + "</label></td>";
                        html += "</tr>";

                    }
                }
                html += "</tbody>";
            }
            html += "</table>";
            html += "<input type=button onclick='SaveFuncs();' value='保存' />";

            $("#docs").html(html);

        }
        //保存功能
        function SaveFuncs() {


            //获得功能列表.
            var dtM = frmData["dtM"];

            var enName = GetQueryString("EnName");

            // HS 标识 hidden show .
            var mypk = webUser.No + "_Funcs_HS_" + enName;
            var cfgEn = new Entity("BP.Sys.UserRegedit");
            cfgEn.SetPKVal(mypk);
            cfgEn.RetrieveFromDBSources();

            //求出来需要所有隐藏的功能分组.
            var Mkeys = ",";
            $.each($('input:checkbox[name=FuncGroup]:checked'), function (i, obj) {
                Mkeys += obj.id + ",";
            });
            //求出来所有隐藏的功能
            var keys = ",";
            $.each($('input:checkbox[name=FuncMethod]:checked'), function (i, obj) {
                keys += obj.id + ",";
            });

            cfgEn.FK_Emp = webUser.No;
            cfgEn.CfgKey = 'Funcs_HS';
            cfgEn.FK_MapData = GetQueryString("EnName");
            cfgEn.MVals = Mkeys;
            cfgEn.Vals = keys;
            cfgEn.Save();
            alert('保存成功.');

        }

    </script>
</head>
<body class="easyui-layout">
    <div data-options="region:'west',title:'设置内容',split:true" style="width:150px;">
        <ul>
            <li><a href="javascript:Help()"><img src="../../Img/Btn/Help.gif" /> 帮助</a></li>
            <li><a href="javascript:Fields()">字段设置</a></li>
            <li><a href="javascript:Funcs()">功能设置</a></li>
        </ul>
    </div>
    <div data-options="region:'center',title:'选择隐藏的字段&功能'" style="padding:5px;">
        <div id="docs">
        </div>
    </div>
</body>
</html>
